package team.zero.lemon.module.workflow.service;

import org.springframework.stereotype.Service;
import team.zero.lemon.common.exception.CustomException;
import team.zero.lemon.common.service.CrudService;
import team.zero.lemon.module.workflow.dao.IActivityParticipantDao;
import team.zero.lemon.module.workflow.entity.ActivityParticipant;
import team.zero.lemon.module.workflow.entity.Parameter.Participants;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by bolin on 2016/11/17.
 */
@Service
public class ParticipantService extends CrudService<IActivityParticipantDao, ActivityParticipant> {


    public List<Participants> findParticipantsByActivityIdOrgId(Integer activityId, Integer orgId) {
        try {
            List<Participants> participantses = new ArrayList<Participants>();
            List<ActivityParticipant> activityParticipants = dao.findParticipantsByActivityIdOrgId(activityId, orgId);
            for (ActivityParticipant activityParticipant : activityParticipants) {
                Participants participants = new Participants();
                participants.setUserId(activityParticipant.getUserId());
                participants.setUserName(activityParticipant.getUserName());
                participants.setProxyUserId(activityParticipant.getUserId());
                participants.setProxyUserName(activityParticipant.getUserName());
                participants.setOrgId(activityParticipant.getOrgId());
                participants.setOrgName(activityParticipant.getOrgName());
                participants.setProxyOrgId(activityParticipant.getOrgId());
                participants.setProxyOrgName(activityParticipant.getOrgName());
                participantses.add(participants);
            }
            return participantses;
        } catch (Exception exc) {
            throw new CustomException(exc);
        }
    }

    public List<Participants> findParticipantsByInstanceIdActivityId(Integer instanceId,Integer activityId) {
        try {
            List<Participants> participantses = new ArrayList<Participants>();
            List<ActivityParticipant> activityParticipants = dao.findParticipantsByInstanceIdActivityId(instanceId,activityId);
            for (ActivityParticipant activityParticipant : activityParticipants) {
                Participants participants = new Participants();
                participants.setUserId(activityParticipant.getUserId());
                participants.setUserName(activityParticipant.getUserName());
                participants.setProxyUserId(activityParticipant.getUserId());
                participants.setProxyUserName(activityParticipant.getUserName());
                participants.setOrgId(activityParticipant.getOrgId());
                participants.setOrgName(activityParticipant.getOrgName());
                participants.setProxyOrgId(activityParticipant.getOrgId());
                participants.setProxyOrgName(activityParticipant.getOrgName());
                participantses.add(participants);
            }
            return participantses;
        } catch (Exception exc) {
            throw new CustomException(exc);
        }
    }
}
